//
//  InfirmaryViewController.m
//  WE
//
//  Created by apple on 15/11/19.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "InfirmaryViewController.h"
#import "Head.h"
#import "BaseView.h"
#import "HospitalHomepageViewController.h"
#import "DoubleDeckView.h"
#import "ProvinceTableViewCell.h"
#import "DepartmentsViewController.h"
#import "RegistrationViewController.h"
#import "LiveCountModel.h"
#import "CellAddView.h"
@interface InfirmaryViewController ()<UITableViewDelegate, UITableViewDataSource>



{
    DoubleDeckView *dtableView;
    CellAddView *cellView;
}

@property (nonatomic, strong)NSArray *cArray;
@property (nonatomic, strong)NSDictionary *pDic;

@end

@implementation InfirmaryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    LiveCountModel *handle = [LiveCountModel mainLiveCountModel];
    if ([handle.string isEqualToString:@"1"]) {
        BaseView *view = [[BaseView alloc] initWithFrame:CGRectMake(0, 64, WindowWidth, 50*Height)];
        [view addTarget:self selector:@selector(pressSkip)];
        view.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:view];
        self.navigationItem.title = self.string;
        
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(20 *Width, 0, 100*Width, 50*Height)];
        textLabel.text = @"去医院微站";
        textLabel.textColor = [UIColor blueColor];
        
        [view addSubview:textLabel];
        
        UILabel *imageL = [[UILabel alloc] initWithFrame:CGRectMake(WindowWidth - 50 *Width, 0, 50*Width, 50*Height)];
        imageL.text = @">";
        imageL.textAlignment = NSTextAlignmentCenter;
        imageL.textColor = [UIColor blackColor];
        [view addSubview:imageL];
        [ToolUtil createLine:64 + 50*Height superView:self.view lift:0 width:WindowWidth hight:1 color:[UIColor grayColor]];
        dtableView = [[DoubleDeckView alloc] initWithFrame:CGRectMake(0, (65 + 50 * Height), WindowWidth, (WindowHeight - (65 + 50 * Height)))];
            [self.view addSubview:dtableView];
    } else {
        UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth, WindowHeight)];
        [self.view addSubview:bView];
        
        
        dtableView = [[DoubleDeckView alloc] initWithFrame:CGRectMake(0, 64 , WindowWidth, WindowHeight - 64)];
        
        dtableView.fatherTable.frame = CGRectMake(0, -64, WindowWidth/2, WindowHeight);
        self.navigationItem.title = @"预约挂号";
        [bView addSubview:dtableView];

    }
    
    
    
    
    
    
    
    
   
    
    self.cArray = @[@"心血管科",@"呼吸内科",@"消化内科",@"神经内科",@"血液科",@"内分泌科",@"儿科"];
    
    self.pDic = @{@"心血管科":self.cArray,@"呼吸内科":self.cArray,@"消化内科":self.cArray,@"神经内科":self.cArray,@"血液科":self.cArray,@"内分泌科":self.cArray,@"儿科":self.cArray};
    
    
    
    
    
    
    dtableView.fatherTable.delegate = self;
    dtableView.fatherTable.dataSource = self;
    dtableView.sonTable.delegate = self;
    dtableView.sonTable.dataSource = self;
    cellView = [[CellAddView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth/2, 50*Height)];
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}

- (void)pressSkip{
    HospitalHomepageViewController *hospitalVC = [[HospitalHomepageViewController alloc] init];
    [self.navigationController pushViewController:hospitalVC animated:YES];
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50*Height;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    
    
    static NSString *pCellString = @"hospitalCell";
    ProvinceTableViewCell *pCell = [tableView dequeueReusableCellWithIdentifier:pCellString];
    if (!pCell) {
        pCell = [[ProvinceTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pCellString];
        
        
        
        
    }
    
    
    if (tableView == dtableView.fatherTable) {
        
        
        NSArray *array = self.pDic.allKeys;
        
        pCell.provinceLabel.text = array[indexPath.row];
        pCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        pCell.backgroundColor = [UIColor  colorWithRed:0.9273 green:0.9273 blue:0.9273 alpha:1.0];
    }else if(tableView == dtableView.sonTable){
        //NSArray *array = [self.pDic valueForKey:@"北京"];
        pCell.provinceLabel.text = self.cArray[indexPath.row];
    }
    
    
    return pCell;
    
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView == dtableView.fatherTable) {
        self.cArray = [self.pDic valueForKey:self.pDic.allKeys[indexPath.row]];
        
        UITableViewCell *cell =tableView.visibleCells[indexPath.row];
        NSArray *array = self.pDic.allKeys;
        //view.backgroundColor = [UIColor whiteColor];
        cellView.label.text = array[indexPath.row];
        [cell addSubview:cellView];

        [dtableView.sonTable reloadData];
    } else {
        
        DepartmentsViewController *departVC = [[DepartmentsViewController alloc] init];
        
        departVC.string =  self.cArray[indexPath.row];
        [self.navigationController pushViewController:departVC animated:YES];
        
        
        
    }
    
}



- (NSInteger)numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == dtableView.fatherTable) {
        return self.pDic.allKeys.count;
    } else {
        return self.cArray.count;
    }
    
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
